package org.laowenchao.dao;

import java.util.Date;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.Query;

import org.laowenchao.pojo.GSMPosition;
import org.laowenchao.server.EMF;

public class GSMPositionDao {
	
	
	public List<GSMPosition> getTracksByDate(Date date) {
		EntityManager em = EMF.get().createEntityManager();
		EntityTransaction t = em.getTransaction();
		t.begin();
		List result = null;
		String query = "select from " + GSMPosition.class.getCanonicalName()
				+ " where date >:start and date <:end";

		result = em.createQuery(query).setParameter("start", date).setParameter(
			"end", new Date(date.getTime() + 24 * 60 * 60 * 1000)).getResultList();
		t.commit();
		em.close();
		return result;

	}
	
	
	
	public static void main(String args[])
	{
		GSMPositionDao dao = new GSMPositionDao();
		dao.getTracksByDate(new Date());
	}
}
